package xin.mashibo.genvictobutest.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.genvict.obusdk.data.CardInformation;

import java.util.ArrayList;
import java.util.List;

import xin.mashibo.genvictobutest.R;

import static xin.mashibo.genvictobutest.constant.ServiceConstant.READCARD_KEY;

public class CardInfoActivity extends AppCompatActivity {

    private CardInformation cardInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        setTitle(R.string.cardInfoActivityTitle);
        Intent intent = getIntent();
        Bundle cardBundle = intent.getBundleExtra(READCARD_KEY);
        cardInfo = cardBundle.getParcelable(READCARD_KEY);
        ListView listView = findViewById(R.id.list_view);
        ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, generateListData());
        listView.setAdapter(adapter);
    }

    /**
     * 启动卡片信息活动
     *
     * @param context 启动的活动
     * @param bundle  bundle
     */
    public static void actionStart(Context context, Bundle bundle) {
        Intent intent = new Intent(context, CardInfoActivity.class);
        intent.putExtra(READCARD_KEY, bundle);
        context.startActivity(intent);
    }

    /**
     * 构建卡片信息列表数据
     *
     * @return 卡片信息列表
     */
    private List<String> generateListData() {
        List<String> dataList = new ArrayList<>(11);
        dataList.add("卡片ID：" + cardInfo.getCardId());
        dataList.add("卡片类型：" + cardInfo.getCardType());
        dataList.add("卡片版本号：" + cardInfo.getCardVersion());
        dataList.add("卡片提供者：" + cardInfo.getProvider());
        dataList.add("卡片发行时间：" + cardInfo.getSignedDate());
        dataList.add("卡片过期时间：" + cardInfo.getExpiredDate());
        dataList.add("卡片中车牌号：" + cardInfo.getVehicleNumber());
        dataList.add("用户类型：" + cardInfo.getCardType());
        dataList.add("卡片中车牌颜色：" + cardInfo.getPlateColor());
        dataList.add("卡片中车辆类型：" + cardInfo.getVehicleModel());
        dataList.add("卡片余额：" + cardInfo.getBalance() + "分");
        return dataList;

    }
}
